#include "async_client.h"
#include "async_session.h"
#include "async_server.h"
#include "signal_dispatcher.h"
int main() {
    asio::io_context io;
    SignalDispatcher dispatcher(io);

    // 启动服务端
    AsyncServer server(io, 12345);
    dispatcher.connect_async(server.signal_new_connection, [&](std::shared_ptr<AsyncSession> session){
        std::cout << "[Server] 新客户端 session=" << session.get() << std::endl;

        dispatcher.connect_async(session->signal_message_received, [session](std::shared_ptr<AsyncSession>, const std::string& msg){
            std::cout << "[Server] 收到消息: " << msg << std::endl;
            session->send("Echo: " + msg);
        });

        dispatcher.connect_async(session->signal_disconnected, [](std::shared_ptr<AsyncSession> s){
            std::cout << "[Server] 客户端断开 session=" << s.get() << std::endl;
        });
    });
    server.start();
    std::cout << "server start over" << std::endl;

    io.run();
}

